package com.haois.ws.common.config.flyway;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;

import javax.sql.DataSource;

/**
 * flyway配置
 *
 * @author sawyerlsy
 * @date 2018-09-19
 * @since
 */
@Configuration
public class FlywayConfig {

    private final ResourceLoader resourceLoader;

    private final DataSource dataSource;


    public FlywayConfig(ResourceLoader resourceLoader, ObjectProvider<DruidDataSource> dataSource) {
        this.resourceLoader = resourceLoader;
        this.dataSource = dataSource.getIfUnique();
    }

    @Bean
    public FlywayMigrationStrategy flywayMigrationStrategy() {
        return flyway -> {
            flyway.migrate();
        };
    }


}
